import os
import shutil
import sys
sys.path.append('/public/home/users/ruc001/bin/aBest')
import vasp

num1=139
nvtstep=1999

potim,nsw,natom,lc,posa=vasp.readvasprun()
print('finished reading')
vela=vasp.velcal(lc,posa,potim)
print('finished calculating')

velas=[[] for i in range(nvtstep,len(vela))]

print(len(vela[0]))
for i in range(nvtstep,len(vela)):
    velas[i-nvtstep]=vela[i][num1]

fvmax,fvmin=vasp.findlimit(velas)

print(fvmax,fvmin,velas[fvmax],velas[fvmin],vela[fvmax+nvtstep][num1],vela[fvmin+nvtstep][num1])

vasp.writepos('POSCAR','pos_vmax',posa[nvtstep+fvmax],vela[nvtstep+fvmax])
vasp.writepos('POSCAR','pos_vmin',posa[nvtstep+fvmin],vela[nvtstep+fvmin])